home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CDsupport / aMiPEG / source / sjrevdct.s.old < prev    next >
Text File  |  1996-02-24  |  13KB  |  782 lines

  1. ;
  2. ; This code implements the basic idct on a 8x8 pixel block.
  3. ; Basically, it's the same as in the JPEG engine, with the sole difference
  4. ; that it's inlined and register-wise a little bit more optimized there.
  5. ;
  6. ; This is a complete rewrite in assembler. Heavy stuff. Lotsa work.
  7. ;
  8. ; Michael Rausch  14-4-94  1:14:00
  9. ;
  10.  
  11. ;
  12. ; The whole code handles D-Frames not very well, but I'll fix it on day.
  13. ;
  14.  
  15.  
  16. DCTSIZE    EQU    8
  17.  
  18. PASS1_BITS EQU    2
  19. CONST_BITS EQU    13
  20.  
  21.  
  22. FIX_0_298631336 EQU    2446    ;1    +    $98e    100110001110
  23. _FIX_0_390180644 EQU    -3196    ;2    -    $c7c
  24. FIX_0_541196100 EQU    4433    ;3    +    $1151    u
  25. FIX_0_765366865 EQU    6270    ;4    +    $187e    u
  26. _FIX_0_899976223 EQU    -7373    ;5    -    $1ccd
  27. FIX_1_175875602 EQU    9633    ;6    +    $25a1
  28. FIX_1_501321110 EQU    12299    ;7    +    $300b
  29. _FIX_1_847759065 EQU    -15137    ;8    -    $3b21    u
  30. _FIX_1_961570560 EQU    -16069    ;9    -    $3ec5
  31. FIX_2_053119869 EQU    16819    ;10    +    $41b3
  32. _FIX_2_562915447 EQU    -20995    ;11    -    $5203
  33. FIX_3_072711026 EQU    25172    ;12    +    $6254
  34.  
  35. ; FIX_1_847759065-FIX_0_765366865 = 2* FIX_0_541196100
  36.  
  37.  
  38. ; **************************************************************************
  39.  
  40. jrevdct:
  41.  
  42.     sub.w    #16,sp
  43.  
  44.     move.l    a0,-(sp)
  45.     lea    compose1(pc),a5
  46.     moveq    #DCTSIZE-1,d7
  47. idct1:    move.l    d7,-(sp)
  48.  
  49.     lea    2(a0),a1
  50.     move.l    (a1)+,d2
  51.     move.l    d2,d0
  52.     move.l    (a1)+,d4
  53.     move.l    (a1)+,d3
  54.     or.l    d4,d0
  55.     or.w    (a1)+,d0
  56.     or.l    d3,d0
  57.     bne.s    idct1_no_ac0
  58.     move.w    (a0),d0
  59.     lsl.w    #PASS1_BITS,d0
  60.     move.w    d0,d1
  61.     swap    d0
  62.     move.w    d1,d0
  63.     REPT    4
  64.     move.l    d0,(a0)+
  65.     ENDR
  66.     bra    idct1_next
  67. idct1_no_ac0:
  68.  
  69.     move.w    d2,d1            ; 2
  70.     add.w    d3,d1            ; 6
  71.     muls    #FIX_0_541196100,d1
  72.     muls    #_FIX_1_847759065,d3
  73.     add.l    d1,d3
  74.     muls    #FIX_0_765366865,d2
  75.     add.l    d1,d2
  76.  
  77.  
  78.     move.w    (a0),d0
  79.     ext.l    d0            ; 0
  80.     ext.l    d4            ; 4
  81.     move.l    d0,d5
  82.     sub.l    d4,d5
  83.     add.l    d0,d4
  84.  
  85.     lsl.l    #5,d4
  86.     lsl.l    #5,d5
  87.     addq.l    #1<<2,d4
  88.     addq.l    #1<<2,d5
  89.     lsl.l    #8,d4
  90.     lsl.l    #8,d5
  91.  
  92.     lea    12(sp),a1    ; top + 2 longs -> 16 bytes platz auf dem stack
  93.     move.l    d4,d0
  94.     add.l    d2,d4
  95.     move.l    d4,(a1)+    ; tmp10
  96.     sub.l    d2,d0
  97.     move.l    d5,d1
  98.     add.l    d3,d5
  99.     move.l    d5,(a1)+    ; tmp11
  100.     sub.l    d3,d1
  101.     move.l    d1,(a1)+    ; tmp12
  102.     move.l    d0,(a1)+    ; tmp13
  103.  
  104. odd_part1: 
  105.     move.w    7*2(a0),d1    ;7
  106.     beq    o0xxx
  107. o1xxx:    move.w    5*2(a0),d2    ;5
  108.     beq    o10xx
  109. o11xx:    move.w    3*2(a0),d3    ;3
  110.     beq    o110x
  111. o111x:    move.w    1*2(a0),d4    ;1
  112.     bne.s    odd1_1111
  113.  
  114.  
  115. ;    7531
  116. odd1_1110:
  117.     move.w    d2,d6
  118.     move.w    d1,d0
  119.     moveq    #0,d4
  120.     bra.s    abk_2
  121.  
  122. ;    7531
  123. odd1_1111:
  124.     move.w    d2,d6
  125.     add.w    d4,d6
  126.     move.w    d1,d0
  127.     add.w    d4,d0
  128.     muls    #FIX_1_501321110,d4
  129. abk_2:    move.w    d1,d5
  130.     add.w    d3,d5
  131.     move.w    d5,d7
  132.     add.w    d6,d7
  133.     muls    #FIX_1_175875602,d7
  134.     muls    #_FIX_1_961570560,d5
  135.     muls    #_FIX_0_390180644,d6
  136.      add.l    d7,d5
  137.     add.l    d7,d6
  138.     move.w    d2,d7
  139.     add.w    d3,d7
  140.     muls    #FIX_0_298631336,d1
  141.     muls    #FIX_2_053119869,d2
  142.     muls    #FIX_3_072711026,d3
  143.     muls    #_FIX_0_899976223,d0
  144.     muls    #_FIX_2_562915447,d7
  145.     add.l    d0,d1
  146.     add.l    d7,d2
  147.     add.l    d5,d1
  148.     add.l    d6,d2
  149.     add.l    d3,d5
  150.     add.l    d4,d6
  151.     add.l    d7,d5
  152.     add.l    d0,d6
  153.     jmp    (a5)
  154.  
  155. o2110x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  156.     bne.s    odd1_1101
  157.  
  158. ;    7531
  159. odd1_1100:
  160.     move.w    d2,d6
  161.     move.w    d1,d3
  162.     moveq    #0,d4
  163.     bra.s    abk_3
  164.  
  165. o110x:    move.w    1*2(a0),d4    ;1
  166.     beq.s    odd1_1100
  167.  
  168. ;    7531
  169. odd1_1101:
  170.     move.w    d2,d6
  171.     move.w    d1,d3
  172.     add.w    d4,d6
  173.     add.w    d4,d3
  174.     muls    #FIX_1_501321110,d4
  175. abk_3:
  176.     move.w    d1,d5
  177.     move.w    d5,d7
  178.     add.w    d6,d7
  179.     muls    #FIX_1_175875602,d7    
  180.     muls    #_FIX_1_961570560,d5
  181.     muls    #_FIX_0_390180644,d6
  182.      add.l    d7,d5
  183.     add.l    d7,d6
  184.     move.w    d2,d0
  185.     muls    #FIX_0_298631336,d1
  186.     muls    #FIX_2_053119869,d2
  187.     muls    #_FIX_0_899976223,d3
  188.     muls    #_FIX_2_562915447,d0
  189.     add.l    d3,d1
  190.     add.l    d0,d2
  191.     add.l    d5,d1
  192.     add.l    d6,d2
  193.     add.l    d4,d6
  194.     add.l    d0,d5
  195.     add.l    d3,d6
  196.     jmp    (a5)
  197.  
  198. o10xx:    move.w    3*2(a0),d3    ;3
  199.     beq    o100x
  200. o101x:    move.w    1*2(a0),d4    ;1
  201.     beq.s    odd1_1010
  202.  
  203. ;    7531
  204. odd1_1011:
  205.     move.w    d1,d5
  206.     add.w    d3,d5
  207.     move.w    d1,d0
  208.     move.w    d4,d6
  209.     add.w    d4,d0
  210.     muls    #FIX_1_501321110,d4
  211.     move.w    d5,d7
  212.     add.w    d6,d7
  213.     muls    #_FIX_0_390180644,d6
  214. abk_4:    muls    #FIX_1_175875602,d7
  215.     muls    #_FIX_1_961570560,d5
  216.     add.l    d7,d6
  217.      add.l    d7,d5
  218.     move.w    d3,d7
  219.     muls    #FIX_0_298631336,d1
  220.     muls    #FIX_3_072711026,d3
  221.     muls    #_FIX_0_899976223,d0
  222.     muls    #_FIX_2_562915447,d7
  223.     add.l    d0,d1
  224.     move.l    d6,d2
  225.     add.l    d5,d1
  226.     add.l    d7,d2
  227.     add.l    d3,d5
  228.     add.l    d4,d6
  229.     add.l    d7,d5
  230.     add.l    d0,d6
  231.     jmp    (a5)
  232.  
  233. o210xx:    move.w    3*DCTSIZE*2(a0),d3    ;3
  234.     beq    o2100x
  235. o2101x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  236.     bne.s    odd1_1011
  237.  
  238. ;    7531
  239. odd1_1010:
  240.     move.w    d1,d5
  241.     add.w    d3,d5
  242.     move.w    d1,d0
  243.     moveq    #0,d4
  244.     move.w    d5,d7
  245.     moveq    #0,d6
  246.     bra.s    abk_4
  247.  
  248. o100x:    move.w    1*2(a0),d4    ;1
  249.     beq.s    odd1_1000
  250.  
  251. ;    7531
  252. odd1_1001:
  253.     move.w    d1,d0
  254.     add.w    d4,d0
  255.     move.w    d1,d5
  256.     move.w    d4,d6
  257.     move.w    d0,d7
  258.     muls    #FIX_1_175875602,d7
  259.     muls    #_FIX_1_961570560,d5
  260.     muls    #_FIX_0_390180644,d6
  261.      add.l    d7,d5
  262.     add.l    d7,d6
  263.     muls    #FIX_0_298631336,d1
  264.     muls    #FIX_1_501321110,d4
  265.     muls    #_FIX_0_899976223,d0
  266.     add.l    d0,d1
  267.     add.l    d5,d1
  268.     move.l    d6,d2
  269.     add.l    d4,d6
  270.     add.l    d0,d6
  271.     jmp    (a5)
  272.  
  273. o2100x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  274.     bne.s    odd1_1001
  275.  
  276. ;    7531
  277. odd1_1000:
  278.     move.w    d1,d2
  279.     move.w    d1,d5
  280.     move.w    d1,d6
  281.     muls    #FIX_1_175875602,d2
  282.     muls    #FIX_1_175875602+_FIX_0_899976223,d6
  283.     muls    #FIX_1_175875602+_FIX_1_961570560,d5
  284.     muls    #FIX_1_175875602+_FIX_0_899976223+_FIX_1_961570560+FIX_0_298631336,d1
  285.     jmp    (a5)
  286.  
  287.  
  288. o0xxx:    move.w    5*2(a0),d2    ;5
  289.     beq    o00xx
  290. o01xx:    move.w    3*2(a0),d3    ;3
  291.     beq    o010x
  292. o011x:    move.w    1*2(a0),d4    ;1
  293.     beq.s    odd1_0110
  294.  
  295. ;    7531
  296. odd1_0111:    ; opt8
  297.     move.w    d2,d6
  298.     add.w    d4,d6
  299.     move.w    d4,d1
  300.     muls    #FIX_1_501321110,d4
  301.     muls    #_FIX_0_899976223,d1
  302. abk_1:    move.w    d2,d0
  303.     add.w    d3,d0
  304.     move.w    d3,d5
  305.  
  306.     move.w    d5,d7
  307.     add.w    d6,d7
  308.     muls    #FIX_1_175875602,d7
  309.     muls    #_FIX_1_961570560,d5
  310.     muls    #_FIX_0_390180644,d6                ; ???? 2
  311.      add.l    d7,d5
  312.     add.l    d7,d6
  313.  
  314.     muls    #FIX_2_053119869,d2
  315.     muls    #FIX_3_072711026,d3
  316.     muls    #_FIX_2_562915447,d0
  317.     add.l    d0,d2
  318.     add.l    d6,d2
  319.     add.l    d4,d6
  320.     add.l    d1,d6
  321.     add.l    d5,d1
  322.     add.l    d3,d5
  323.     add.l    d0,d5
  324.     jmp    (a5)
  325.  
  326. o20xxx:    move.w    5*DCTSIZE*2(a0),d2    ;5
  327.     beq    o200xx
  328. o201xx:    move.w    3*DCTSIZE*2(a0),d3    ;3
  329.     beq.s    o2010x
  330. o2011x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  331.     bne.s    odd1_0111
  332.  
  333. ;    7531
  334. odd1_0110:
  335.     move.w    d2,d6
  336.     moveq.l    #0,d1
  337.     moveq.l    #0,d4
  338.     bra.s    abk_1
  339.  
  340. o010x:    move.w    1*2(a0),d4    ;1
  341.     beq.s    odd1_0100
  342.  
  343. ;    7531
  344. odd1_0101:
  345.     move.w    d2,d6
  346.     move.w    d2,d7
  347.     add.w    d4,d6
  348.     move.w    d4,d1
  349.     move.w    d6,d5
  350.     muls    #FIX_1_175875602,d5
  351.     muls    #_FIX_0_390180644+FIX_1_175875602,d6
  352.     muls    #FIX_2_053119869+_FIX_2_562915447,d2
  353.     muls    #FIX_1_501321110,d4
  354.     muls    #_FIX_0_899976223,d1
  355.     muls    #_FIX_2_562915447,d7
  356.     add.l    d6,d2
  357.     add.l    d1,d6
  358.     add.l    d5,d1
  359.     add.l    d7,d5
  360.     add.l    d4,d6
  361.     jmp    (a5)
  362.  
  363. o2010x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  364.     bne.s    odd1_0101
  365.  
  366. ;    7531
  367. odd1_0100:
  368.     move.w    d2,d6
  369.     move.w    d2,d1
  370.     move.w    d2,d5
  371.     muls    #FIX_1_175875602,d1
  372.     muls    #FIX_1_175875602+_FIX_2_562915447,d5
  373.     muls    #FIX_1_175875602+_FIX_0_390180644,d6
  374.     muls    #FIX_1_175875602+_FIX_2_562915447+_FIX_0_390180644+FIX_2_053119869,d2
  375.     jmp    (a5)
  376.  
  377. o00xx:    move.w    3*2(a0),d5    ;3
  378.     beq.s    o000x
  379. o001x:    move.w    1*2(a0),d4    ;1
  380.     beq.s    odd1_0010
  381.  
  382. ;    7531
  383. odd1_0011:    ; opt12
  384.     move.w    d5,d2
  385.     move.w    d5,d3
  386.     move.w    d4,d1
  387.     move.w    d4,d6
  388.     move.w    d3,d7
  389.     add.w    d4,d7
  390.     muls    #FIX_1_175875602,d7
  391.     muls    #_FIX_1_961570560,d5
  392.     muls    #_FIX_0_390180644,d6
  393.      add.l    d7,d5
  394.     add.l    d7,d6
  395.     muls    #_FIX_2_562915447+FIX_3_072711026,d3
  396.     muls    #_FIX_0_899976223+FIX_1_501321110,d4
  397.     muls    #_FIX_0_899976223,d1
  398.     muls    #_FIX_2_562915447,d2
  399.     add.l    d5,d1
  400.     add.l    d6,d2
  401.     add.l    d3,d5
  402.     add.l    d4,d6
  403.     jmp    (a5)
  404.  
  405. o200xx:    move.w    3*DCTSIZE*2(a0),d5    ;3
  406.     beq    o2000x
  407. o2001x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  408.     bne.s    odd1_0011
  409.  
  410. ;    7531
  411. odd1_0010:
  412.     move.w    d5,d6
  413.     move.w    d5,d2
  414.     move.w    d5,d1
  415.     muls    #FIX_1_175875602,d6
  416.     muls    #FIX_1_175875602+_FIX_2_562915447,d2
  417.     muls    #FIX_1_175875602+_FIX_1_961570560,d1
  418.     muls    #FIX_1_175875602+_FIX_2_562915447+_FIX_1_961570560+FIX_3_072711026,d5
  419.     jmp    (a5)
  420.  
  421. o000x:    move.w    1*2(a0),d6    ;1
  422.     beq.s    odd1_0000
  423.  
  424. ;    7531
  425. odd1_0001:    ; opt 14
  426.     move.w    d6,d5
  427.     move.w    d6,d1
  428.     move.w    d6,d2
  429.     muls    #FIX_1_175875602,d5
  430.     muls    #FIX_1_175875602+_FIX_0_899976223,d1
  431.     muls    #FIX_1_175875602+_FIX_0_390180644,d2
  432.     muls    #FIX_1_175875602+_FIX_0_899976223+_FIX_0_390180644+FIX_1_501321110,d6
  433.     jmp    (a5)
  434.  
  435. ; priority: 14 12 8 0 
  436.  
  437. ;    7531
  438. odd1_0000:
  439.     moveq    #CONST_BITS-PASS1_BITS,d7    ; optimized compose !
  440.  
  441.     lea    12(sp),a1
  442.     move.l    (a1)+,d0    ; tmp10
  443.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d0
  444.     move.l    (a1)+,d1    ; tmp11
  445.     lsr.l    d7,d1
  446.     move.w    d1,d0
  447.  
  448.     move.l    (a1)+,d2    ; tmp12
  449.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d2
  450.     move.l    (a1)+,d3    ; tmp13
  451.     lsr.l    d7,d3
  452.     move.w    d3,d2
  453.  
  454.     move.l    d0,(a0)+
  455.     swap    d0
  456.     move.l    d2,(a0)+
  457.     swap    d2
  458.     move.l    d2,(a0)+
  459.     move.l    d0,(a0)+
  460.  
  461.     move.l    (sp)+,d7
  462.     dbra    d7,idct1
  463.     bra.s    idct1_ready
  464.  
  465. ; keep 1 2 5 6
  466.  
  467. compose1: moveq    #CONST_BITS-PASS1_BITS,d7
  468.  
  469.     lea    12(sp),a1
  470.     move.l    (a1)+,d4    ; tmp10
  471.     sub.l    d6,d4
  472.     add.l    d6,d6
  473.     add.l    d4,d6
  474.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d6
  475.     move.l    (a1)+,d3    ; tmp11
  476.     sub.l    d5,d3
  477.     add.l    d5,d5
  478.     add.l    d3,d5
  479.     lsr.l    d7,d5
  480.     move.w    d5,d6
  481.     move.l    d6,(a0)+
  482.     move.l    (a1)+,d6    ; tmp12
  483.     sub.l    d2,d6
  484.     add.l    d2,d2
  485.     add.l    d6,d2
  486.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d2
  487.     move.l    (a1)+,d5    ; tmp13
  488.     sub.l    d1,d5
  489.     add.l    d1,d1
  490.     add.l    d5,d1
  491.     lsr.l    d7,d1
  492.     move.w    d1,d2
  493.     move.l    d2,(a0)+
  494.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d5
  495.     lsr.l    d7,d6
  496.     move.w    d6,d5
  497.     move.l    d5,(A0)+
  498.     lsl.l    #16-(CONST_BITS-PASS1_BITS),d3
  499.     lsr.l    d7,d4
  500.     move.w    d4,d3
  501.     move.l    d3,(a0)+
  502.  
  503. idct1_next:
  504.     move.l    (sp)+,d7
  505.     dbra    d7,idct1
  506.  
  507. idct1_ready:
  508. ; *******************************************************
  509.  
  510.     move.l    (sp)+,a0
  511.     lea    compose2(pc),a5
  512.     moveq    #DCTSIZE-1,d7
  513. idct2:    move.l    d7,-(sp)
  514.  
  515.  
  516. odd_part2: 
  517.     move.w    7*DCTSIZE*2(a0),d1    ;7
  518.     beq    o20xxx
  519. o21xxx:    move.w    5*DCTSIZE*2(a0),d2    ;5
  520.     beq    o210xx
  521. o211xx:    move.w    3*DCTSIZE*2(a0),d3    ;3
  522.     beq    o2110x
  523. o2111x:    move.w    1*DCTSIZE*2(a0),d4    ;1
  524.     beq    odd1_1110
  525.     bra    odd1_1111
  526.  
  527. o2000x:    move.w    1*DCTSIZE*2(a0),d6    ;1
  528.     bne    odd1_0001
  529.  
  530. odd0_0000:
  531.     move.w    2*DCTSIZE*2(a0),d2
  532.     move.w    4*DCTSIZE*2(a0),d4
  533.     move.w    6*DCTSIZE*2(a0),d3
  534.     move.w    d2,d0
  535.     add.w    d3,d0
  536.     muls    #FIX_0_541196100/4,d0
  537.     muls    #_FIX_1_847759065/4,d3
  538.     add.l    d0,d3
  539.     muls    #FIX_0_765366865/4,d2
  540.     add.l    d0,d2
  541.  
  542.     move.w    (a0),d0
  543.     add.w    #1<<(PASS1_BITS+3-1),d0        ; precalc from the descaling part below
  544.     ext.l    d4
  545.     ext.l    d0
  546.     move.l    d0,d5
  547.     sub.l    d4,d5
  548.     add.l    d0,d4
  549.  
  550.     moveq    #CONST_BITS-2,d0
  551.     lsl.l    d0,d4
  552.     lsl.l    d0,d5
  553.  
  554.     move.l    d4,d0
  555.     add.l    d2,d4
  556.     swap     d4
  557.     move.w    d4,(a0)+
  558.     sub.l    d2,d0
  559.     move.w    d4,7*DCTSIZE*2-2(a0)
  560.     swap    d0
  561.     move.w    d0,3*DCTSIZE*2-2(a0)
  562.     move.l    d5,d4
  563.     move.w    d0,4*DCTSIZE*2-2(a0)
  564.     add.l    d3,d5
  565.     swap     d5
  566.     sub.l    d3,d4
  567.     move.w    d5,1*DCTSIZE*2-2(a0)
  568.     swap    d4
  569.     move.w    d5,6*DCTSIZE*2-2(a0)
  570.     move.w    d4,2*DCTSIZE*2-2(a0)
  571.     move.w    d4,5*DCTSIZE*2-2(a0)
  572.  
  573.     move.l    (sp)+,d7
  574.     dbra    d7,idct2
  575.     bra    idct2_ready
  576.  
  577.  
  578. compose2:
  579.     move.w    2*DCTSIZE*2(a0),d3
  580.     move.w    4*DCTSIZE*2(a0),d4
  581.     move.w    6*DCTSIZE*2(a0),d7
  582.  
  583.     move.w    d3,d0
  584.     add.w    d7,d0
  585.     muls    #FIX_0_541196100,d0
  586.     muls    #_FIX_1_847759065,d7
  587.     add.l    d0,d7
  588.     muls    #FIX_0_765366865,d3
  589.     add.l    d0,d3
  590.  
  591.     asr.l    #2,d7
  592.     asr.l    #2,d3
  593.     move.l    d7,a3
  594.  
  595.     move.w    (a0),d0
  596.     add.w    #1<<(PASS1_BITS+3-1),d0    ; precalc from the descaling part below
  597.     ext.l    d4
  598.     ext.l    d0
  599.     move.l    d0,d7
  600.     sub.l    d4,d7
  601.     add.l    d0,d4
  602.  
  603.     moveq    #CONST_BITS-2,d0
  604.     lsl.l    d0,d4
  605.     lsl.l    d0,d7
  606.  
  607.  
  608.     asr.l    #2,d6
  609.     asr.l    #2,d5
  610.     asr.l    #2,d2
  611.     asr.l    #2,d1
  612.  
  613.  
  614.     move.l    d4,d0
  615.     add.l    d3,d4
  616.     sub.l    d3,d0
  617.  
  618.     move.l    d7,d3
  619.     add.l    a3,d7
  620.     sub.l    a3,d3
  621.  
  622.  
  623.     sub.l    d6,d4
  624.     add.l    d6,d6
  625.     add.l    d4,d6
  626.  
  627.     swap    d6                ; moveq    #CONST_BITS+PASS1_BITS+3  -2   ,d6   ;   asr.l d6,d3
  628.     move.w    d6,(a0)+
  629.     swap    d4
  630.     move.w    d4,7*DCTSIZE*2-2(a0)
  631.  
  632.     sub.l    d1,d0
  633.     add.l    d1,d1
  634.     add.l    d0,d1
  635.  
  636.     swap    d1
  637.     move.w    d1,3*DCTSIZE*2-2(a0)
  638.     swap    d0
  639.     move.w    d0,4*DCTSIZE*2-2(a0)
  640.  
  641.     sub.l    d5,d7
  642.     add.l    d5,d5
  643.     add.l    d7,d5
  644.  
  645.     swap    d5
  646.     move.w    d5,1*DCTSIZE*2-2(a0)
  647.     swap    d7
  648.     move.w    d7,6*DCTSIZE*2-2(a0)
  649.  
  650.     sub.l    d2,d3
  651.     add.l    d2,d2
  652.     add.l    d3,d2
  653.  
  654.     swap    d2
  655.     move.w    d2,2*DCTSIZE*2-2(a0)
  656.     swap    d3
  657.     move.w    d3,5*DCTSIZE*2-2(a0)
  658.  
  659. idct2_next:
  660.     move.l    (sp)+,d7
  661.     dbra    d7,idct2
  662.  
  663. idct2_ready;
  664.     add.w    #16,sp
  665. ;    movem.l    (sp)+,JREVDCTREGS
  666.  
  667.     movem.l    (sp)+,ri_regs
  668.     rts
  669.  
  670.  
  671.     XDEF    @j_rev_dct
  672. @j_rev_dct:
  673.     movem.l    ri_regs,-(sp)
  674.     bra    jrevdct
  675.  
  676.  
  677.     ifeq    1
  678. ; **************************************************************************
  679.  
  680. ; Pre compute singleton coefficient IDCT values.
  681. ;
  682. ; void init_pre_idct(void)
  683.  
  684. ;    XDEF @init_pre_idct
  685. @init_pre_idct:
  686.     movem.l    d2/a2,-(sp)
  687.  
  688.     lea    PreIDCT,a2
  689.     move.w    #64*64/4/4-1,d2
  690. preidctclr:
  691.     clr.l    (a2)+
  692.     clr.l    (a2)+
  693.     clr.l    (a2)+
  694.     clr.l    (a2)+
  695.     dbra    d2,preidctclr
  696.  
  697.     lea    PreIDCT+63*64*2,a2
  698.     moveq    #63,d2
  699. preidctloop:
  700.     move.w    #2048,(a2,d2.w)
  701.     move.l    a2,a0
  702.     bsr    @j_rev_dct
  703.     sub.w    #64,a2
  704.     dbra    d2,preidctloop
  705.  
  706.     movem.l    (sp)+,d2/a2
  707.     rts
  708.  
  709. ; ************************************************************************************
  710.  
  711. ; Perform the inverse DCT on one block of coefficients.
  712. ;
  713. ; void j_rev_dct_sparse (DCTBLOCK data, int pos)  
  714.  
  715. ;    XDEF    @j_rev_dct_sparse
  716. @j_rev_dct_sparse:
  717.  
  718.     tst.l    d0
  719.     bne    itsnotthedc
  720.  
  721. ; the single element to cope with is the dc coefficient
  722.  
  723.     move.w    (a0),d1
  724.     bpl.s    scale_dc
  725.     subq.w    #3+4,d1                ; "implement" the rounding error
  726. scale_dc:addq.w    #4,d1
  727.     asr.w    #3,d1
  728.  
  729.     move.w    d1,d0                ; extend to longword
  730.     swap    d0
  731.     move.w    d1,d0
  732.  
  733.     moveq    #7,d1
  734. set_dc:    move.l    d0,(a0)+
  735.     move.l    d0,(a0)+
  736.     move.l    d0,(a0)+
  737.     move.l    d0,(a0)+
  738.     dbra    d1,set_dc
  739.  
  740.     rts                    ; not that pretty
  741. ;    bra    exit_jrds
  742. itsnotthedc:
  743.     movem.l    d2/d3,-(sp)
  744.  
  745. ; Some other coefficient. 
  746.  
  747.     move.w    (a0,d0.w),d1        ; get coeff
  748.  
  749.     lea    PreIDCT,a1        ; get precalculated DCT
  750.     lsl.l    #7,d0
  751.     add.l    d0,a1
  752.  
  753.     moveq    #CONST_BITS-PASS1_BITS-8,d3    ; scale down
  754.  
  755.     moveq.l    #31,d0
  756. set_ac:    move.w    d1,d2
  757.     muls    (a1)+,d2
  758.     lsr.l    d3,d2
  759.     move.w    d2,(a0)+
  760.     move.w    d1,d2
  761.     muls    (a1)+,d2
  762.     lsr.l    d3,d2
  763.     move.w    d2,(a0)+
  764.     dbra    d0,set_ac
  765.  
  766.     movem.l    (sp)+,d2/d3
  767. exit_jrds: rts
  768.  
  769. ; ************************************************************************************
  770.  
  771.     section bss,BSS
  772.  
  773. ;
  774. ; Precomputed idct value arrays
  775. ;
  776. PreIDCT: ds.w    64*64
  777.  
  778.     endc
  779.  
  780.  
  781. ;    END
  782.